<?php


namespace Module\Department\Admin\Controller;


use Illuminate\Routing\Controller;
use ModStart\Admin\Concern\HasAdminQuickCRUD;
use ModStart\Admin\Layout\AdminCRUDBuilder;
use ModStart\Form\Form;
use ModStart\Grid\GridFilter;
use ModStart\Support\Concern\HasFields;
use Module\Department\Model\Department;
use Module\Department\Util\DepartmentUtil;

class DepartmentController extends Controller
{
    use HasAdminQuickCRUD;

    protected function crud(AdminCRUDBuilder $builder)
    {
        $builder
            ->init('department')
            ->field(function ($builder) {
                /** @var HasFields $builder */
                $builder->id('id', 'ID');
                $builder->text('name','部门名称');
                $builder->text('content','部门描述');
                $builder->select('userId','负责人')->optionModel('admin_user','id','username')->required();
                $builder->display('created_at', L('Created At'))->listable(false);
                $builder->display('updated_at', L('Updated At'))->listable(false);
            })
            ->gridFilter(function (GridFilter $filter) {
                $filter->eq('id', L('ID'));
            })
            ->hookChanged(function (Form $form){
                DepartmentUtil::clearCache();
            })
            ->title('部门管理');
    }
}